package part1.q1;

import java.util.Stack;

public class MyStack1 {
	
	private Stack<Integer> stackData;
	private Stack<Integer> stackMin;
	
	
	public MyStack1() {
		stackData = new Stack<Integer>();
		stackMin = new Stack<Integer>();
	}
	
	
	
	public void push(int newNum) {
		if(stackMin.isEmpty()) {
			stackMin.push(newNum);
		}
		if(newNum <= getMin()) {
			stackMin.push(newNum);
		}
		stackData.push(newNum);
	}
	
	
	public int pop() {
		if(stackData.isEmpty()) {
			throw new RuntimeException("Your stack is empty.");
		}
		int value = stackData.pop();
		if(value == getMin()) {
			stackMin.pop();
		}
		return value;
	}
	
	
	public int getMin() {
		if(stackMin.isEmpty()) {
			throw new RuntimeException("Your stack is empty.");
		}
		return stackMin.peek();
	}
	
	
	
	
	
	
	
	
	
	
	public static void main(String[] args) {
		MyStack1 myStack1 = new MyStack1();
		myStack1.push(3);
		myStack1.push(4);
		myStack1.push(5);
		myStack1.push(1);
		myStack1.push(2);
		myStack1.push(1);
		System.out.println( "min : " + myStack1.getMin());
		System.out.println(myStack1.pop());
		System.out.println(myStack1.pop());
		// System.out.println(myStack1.pop());
		
		System.out.println("------");
		System.out.println("min : " + myStack1.getMin());
		
		
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
}
